package mvc.service;

import java.lang.reflect.Field;
import java.util.Map;


public class ActionBean {

	/**
	 * 对页面传递过来的参数通过java反射给xml配置的javabean进行赋值
	 * @param beanClass
	 * @param request
	 * @return
	 */
	public static ActionObject actionBean(String beanClass,Map<String,String> map){
		ActionObject object =null;
		try{
			Class clazz=Class.forName(beanClass);
			object=(ActionObject)clazz.newInstance();
			Field[] fields=clazz.getDeclaredFields();
			for(Field field:fields){
				  String fieldName = field.getName();
	                //赋值
	                field.setAccessible(true);
	                field.set(object, map.get(fieldName));//request.getParameter(fieldName)
	                field.setAccessible(false);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return object;
	}
}
